package me.eachann.session.sample

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import me.eachann.session.SessionManager
import me.eachann.session.SessionStateChangedListener

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        SessionManager.addSessionStateChangedListener(object : SessionStateChangedListener {
            override fun onSessionStateChanged(session: Any?) {
                if (session is Token) {
                    Log.i("MainActivity", "onSessionStateChanged：" + session.token)
                }
            }
        })
        SessionManager.setSession(Token("hello"))
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
        Log.i("MainActivity", "登录信息：" + SessionManager.getSession<Token>(Token::class.java)?.token)
    }

    override fun onDestroy() {
        super.onDestroy()
        SessionManager.clearListeners()
        SessionManager.clearAll()
    }
}
